<?php
require_once "/pdo/pdo_connect.php";

function createMateriel($unmateriel)
{
    $pdo=  open();
    $query = "INSERT INTO materiel VALUES ('','".addslashes($unmateriel["nommateriel"])."', '".$unmateriel["quantite"]."', '".addslashes($unmateriel["photo"])."');";
     $pdo->exec($query);
}
    
function readOneMateriel($reference)
{
    $pdo=  open();
    $query = "SELECT * FROM materiel WHERE reference=$reference;";
    $uncontact = $pdo->query($query)->fetch();
    return $uncontact;
}

function readAllMateriel()
{
    $pdo=  open();
    $query = 'SELECT * FROM materiel;';
    $cursor = $pdo->query($query);
    $lescontacts = $cursor->fetchAll();
    return $lescontacts;
}

function updateMateriel($unmateriel)
{
    $pdo=  open();
    $query = "UPDATE materiel SET  nommateriel='".addslashes($unmateriel["nommateriel"])."', quantite=".$unmateriel["quantite"].", photo='".addslashes($unmateriel["photo"])."' where reference=".$unmateriel["reference"].";";
    $pdo->exec($query);    
}

function deleteMateriel($reference)
{
    $pdo=  open();
    $query = "DELETE FROM materiel WHERE reference=$reference;";
    $pdo->exec($query);    
}

function existMateriel($nommateriel)
{
    $pdo=  open();
    $query = "SELECT * FROM materiel WHERE nommateriel='$nommateriel';";
    $statement = $pdo->query($query);
    return $statement->rowCount();
}

?>
